﻿using LD.Host;
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using YTE.Control;

namespace LD.Tool
{
    public partial class FrmVariable : FrmOKCancel
    {
        public FrmVariable()
        {
            InitializeComponent();
            this.Shown += FrmVariable_Shown;
            this.treeViewY1.ExpandAll();
            this.btn_ok.Click += Btn_ok_Click;
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            var node = this.treeViewY1.SelectedNode;
            if (node != null && node.Parent != null)
            {
                SelectVal = node.Text;
            }
            else
            {
                SelectVal = string.Empty;
            }
        }
        public string SelectVal
        {
            get; private set;
        }
        private void FrmVariable_Shown(object sender, EventArgs e)
        {
            Loader();
        }
        private void Loader()
        {
            this.treeViewY1.Nodes.Clear();
            //var list =CacheHelper1 CacheHelper.Instance.GetList.Select(p => (p.Value as TB_Variable)).ToList();
            //var main = list.Where(p => p.PId == 0 && !p.IsHide).ToList();
            //foreach (var item in main)
            //{
            //    TreeNode tree = new TreeNode();
            //    tree.Text = item.Name;
            //    tree.SelectedImageIndex = 1;
            //    tree.ImageIndex = 0;

            //    var childs = list.Where(p => p.PId == item.Id && !p.IsHide).ToList();
            //    foreach (var child in childs)
            //    {
            //        TreeNode tree_child = new TreeNode();
            //        tree_child.Text = child.Name;
            //        tree_child.SelectedImageIndex = 1;
            //        tree_child.ImageIndex = 2;
            //        tree.Nodes.Add(tree_child);
            //    }
            //    this.treeViewY1.Nodes.Add(tree);
            //}
        }

        public void MRefresh()
        {
            Loader();
        }
        private void treeViewY1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {

        }
    }
}
